# aem.two_d.transient.evaporation -- 
#
# Copyright (c) 2000, V.Kelson and M.Bakker
#           (c) 2001, Willem Jan Zaadnoordijk

from types import *

import geometry
XY = geometry.XY
SearchableList = geometry.two_d.collections.SearchableList

import base

import aem.container
RowList = aem.container.RowList
ColumnList = aem.container.ColumnList
 
class Evaporation(base.Element):
	'''Class for transient evaporation

	Python call: Evaporation(tElist=[geometry.XY(0,0)],parent=None)

	Attributes:

	  - tElist:  list of pairs (time, discharge)
	  - parent: parent of the element (inherited from Element)
	  - elementList: list of transient elements ("UnitStepEvaporation"s)

	Overloaded functions from Element: __init__,
	                                   potentialInfluence, dischargeInfluence
	'''
	
	def __init__(self,tElist=[geometry.XY(0,0)],parent=None):
		'''Constructor'''
		base.Element.__init__(self,parent)
		self.elementList = SearchableList()
		self.__numberOfParameters = 0
		self.parameters=ColumnList([])
		for partim in tElist :
			if partim.x > 0 :
				self.__numberOfParameters = self.__numberOfParameters+1
				if (self.__numberOfParameters > 1) :
					dE=partim.y-self.parameters[self.__numberOfParameters-2]
				else :
					dE=partim.y
				aem.two_d.transient.UnitStepEvaporation(partim.x,self)
				self.parameters.append(dE)

	def __repr__(self):
		return 'Trans.Evaporation{'    \
		   + str((self.parameters,self.elementList)) \
		   + '}'

	def addElement(self,el):
		self.elementList.append(el)

	def potentialInfluence(self,xy,t):
		pot=[]
		self.alpha=self.parent.aquiferDiffusivity(xy,t)
		for el in self.elementList:
			pot = pot + el.potentialInfluence(xy,t)
		return RowList( pot )

	def dischargeInfluence(self,xy,t):
		dis=[]
		self.alpha=self.parent.aquiferDiffusivity(xy,t)
		for el in self.elementList :
			dis = dis + el.dischargeInfluence(xy,t)
		return RowList( dis )

	def rechargeInfluence(self,xy,t):
		'''Returns recharge influence as RowList
		
		Returns the recharge influence function(s) for the element at
		the point xy, as an array. The return values are
		stored in a row vector, one entry per unknown.'''
		rech=[]
		self.alpha=self.parent.aquiferDiffusivity(xy,t)
		for el in self.elementList :
			rech = rech + el.rechargeInfluence(xy,t)
		return RowList( rech )
